package com.g001.model;

import java.util.Random;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

public class Clouds extends Entity {
	
	private Image[] images ;
	private final static int WIDTH = 512;
	private final static int HEIGHT = 170;
	private final Vector2f[] positions;
	private Random random = new Random();
	
	public Clouds(final String name, final String path, final Vector2f position) throws SlickException{
		super(name, path, position);
		images = new Image[4];
		positions = new Vector2f[images.length];
		for(int i=0; i<images.length; i++){
			positions[i] = new Vector2f(position.x+random.nextInt(800),position.y+random.nextInt(200));
		}
		images[0] = image.getSubImage(0, HEIGHT, WIDTH, HEIGHT).getScaledCopy(2);
		images[1] = image.getSubImage(0, 0, WIDTH, HEIGHT).getScaledCopy(2);
		images[2] = image.getSubImage(0, 2*HEIGHT, WIDTH/2, HEIGHT).getScaledCopy(2);
		images[3] = image.getSubImage(WIDTH/2, 2*HEIGHT, WIDTH/2, HEIGHT).getScaledCopy(2);
		
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		for(int i=0; i<images.length; i++){
			g.drawImage(images[i], positions[i].x, positions[i].y);
		}
		
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		for(int i=0; i<positions.length; i++){
			if(positions[i].x<=container.getWidth())
				positions[i].x+=.01f*i*delta;
			else
				positions[i].x = -images[i].getWidth();
		}
	}


}
